<?php

if(! defined('OT_ROOT')) {
	exit('Access Denied');
}


class Url{

	public static function ListRefMark($typeStr, $typeStr2, $typeStr3, $page=0, $domain=''){
		global $GB_WebHost,$systemArr;

		if (strlen($typeStr3)>0){
			if ($typeStr == 'refer' && $typeStr2 == 'theme' && $systemArr['SYS_searchUrlMode'] == 1){
				if (strlen($domain) == 0){ $domain = $GB_WebHost; }
				return $domain .'search/'. OT::UrlEn($typeStr2);
			}else{
				$typeStr .= '-'. $typeStr2 .'-'. OT::UrlEn($typeStr3);
			}
		}else{
			if ($typeStr == 'mark' && $systemArr['SYS_tagUrlMode'] == 1){
				if (strlen($domain) == 0){ $domain = $GB_WebHost; }
				return $domain .'tag/'. OT::UrlEn($typeStr2);
			}else{
				$typeStr .= '-'. OT::UrlEn($typeStr2);
			}
		}

		return self::ListStr($typeStr, $page, $domain);
	}

	public static function ListStr($typeStr, $page=0, $domain=''){
		global $GB_WebHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		switch ($systemArr['SYS_newsListUrlMode']){
			case 'html-2.x':
				if ($systemArr['SYS_diyInfoTypeDir'] == 1 && strpos('|announ|new|','|'. $typeStr .'|') !== false){
					if ($page > 1){ $pageStr='index_'. $page .'.html'; }else{ $pageStr=''; }
					$retStr = $domain . $typeStr .'/'. $pageStr;
				}else{
					if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
					if (strpos($typeStr,'-') !== false){
						$retStr = $domain .'news/?list_'. $typeStr . $pageStr .'.html';
					}else{
						$retStr = $domain . $systemArr['SYS_newsListFileName'] .'/list_'. $typeStr . $pageStr .'.html';
					}
				}
				break;
		
			case 'static-3.x':
				if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
				if (strpos($typeStr,'-') !== false){
					$retStr = $domain .'news/?list_'. $typeStr . $pageStr .'.html';
				}else{
					$retStr = $domain . $systemArr['SYS_newsListFileName'] .'/list_'. $typeStr . $pageStr .'.html';
				}
				break;

			case 'dyn-2.x':
				if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
				$retStr = $domain .'news/?list_'. $typeStr . $pageStr .'.html';
				break;

		}
		return $retStr;
	}

	public static function ListID($htmlName, $infoTypeDir, $dataID, $page=0, $domain='', $maxPage=0){
		global $GB_WebHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		switch ($systemArr['SYS_newsListUrlMode']){
			case 'html-2.x':
				if ($maxPage > 0 && $maxPage < $page){
					if ($page > 1){ $pageStr = '_'. $page; }else{ $pageStr = ''; }
					$retStr = $domain .'news/?list_'. $dataID . $pageStr .'.html';
				}else{
					if ($systemArr['SYS_diyInfoTypeDir'] == 1 && strlen($infoTypeDir) >= 1){
						if ($page > 1){ $pageStr = 'index_'. $page .'.html'; }else{ $pageStr = ''; }
						if (substr($infoTypeDir,-1) != '/'){ $infoTypeDir .= '/'; }
						$retStr = $domain . $infoTypeDir . $pageStr;
					}else{
						if ($htmlName == ''){ $htmlName = $dataID; }
						if ($page > 1){ $pageStr = '_'. $page; }else{ $pageStr = ''; }
						$retStr = $domain . $systemArr['SYS_newsListFileName'] .'/list_'. $htmlName . $pageStr .'.html';
					}
				}
				break;

			case 'static-3.x':
				if ($htmlName == ''){ $htmlName = $dataID; }
				if ($page > 1){ $pageStr = '_'. $page; }else{ $pageStr = ''; }
				$retStr = $domain . $systemArr['SYS_newsListFileName'] .'/list_'. $htmlName . $pageStr .'.html';
				break;

			case 'dyn-2.x':
				if ($page > 1){ $pageStr = '_'. $page; }else{ $pageStr = ''; }
				$retStr = $domain .'news/?list_'. $dataID . $pageStr .'.html';
				break;

		}
		return $retStr;
	}

	public static function ListTypeID($listType, $dataID, $page=0, $domain=''){
		global $GB_WebHost;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
		$retStr = $domain .'news/?list_'. $listType .'-'. $dataID . $pageStr .'.html';

		return $retStr;
	}

	public static function ListUrl($urlMode, $urlStr, $urlIsEnc=0, $urlId=0, $urlWebPathPart='', $pcUrl=''){
		if ($pcUrl == ''){ $pcUrl = $urlWebPathPart; }
		if ($urlMode == 'url' && $urlIsEnc){
			return $pcUrl .'p.php?m=url&t=infoType&id='. $urlId;
		}else{
			return str_replace('{%网站根路径%}', $urlWebPathPart, $urlStr);
		}
	}

	public static function NewsID($infoTypeDir, $datetimeDir, $dataID, $page=0, $domain=''){
		global $GB_WebHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		switch ($systemArr['SYS_newsShowUrlMode']){
			case 'html-2.x': case 'static-3.x':
				if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
				if ($systemArr['SYS_htmlInfoTypeDir']==1 && strlen($infoTypeDir)>=1){ $infoTypeHtmlDir=$infoTypeDir; }else{ $infoTypeHtmlDir=''; }
				if ($systemArr['SYS_htmlDatetimeDir']>0 && strlen($datetimeDir)>=1){ $datetimeHtmlDir=$datetimeDir; }else{ $datetimeHtmlDir=''; }
				if ($systemArr['SYS_diyInfoTypeDir']==1){
					$retStr = $domain . $infoTypeHtmlDir . $datetimeHtmlDir . $dataID . $pageStr .'.html';
				}else{
					$retStr = $domain . $systemArr['SYS_newsShowFileName'] .'/'. $infoTypeHtmlDir . $datetimeHtmlDir . $dataID . $pageStr .'.html';
				}
				break;

			case 'dyn-2.x':
				if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
				$retStr = $domain .'news/?'. $dataID . $pageStr .'.html';
				break;

		}
		return $retStr;
	}

	public static function NewsUrl($urlStr, $urlIsEnc=0, $urlId=0 ,$urlWebPathPart=''){
		if ($urlIsEnc){
			return $urlWebPathPart .'p.php?m=url&t=info&id='. $urlId;
		}else{
			return $urlStr;
		}
	}

	public static function WebID($dataID, $page=0, $domain=''){
		global $GB_WebHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		switch ($systemArr['SYS_dynWebUrlMode']){
			case 'html-2.x': case 'static-3.x':
				if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
				$retStr = $domain . $systemArr['SYS_dynWebFileName'] .'/web_'. $dataID . $pageStr .'.html';
				break;

			case 'dyn-2.x':
				if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
				$retStr = $domain .'news/?web_'. $dataID . $pageStr .'.html';
				break;

		}
		return $retStr;
	}

	public static function WebUrl($urlStr, $urlIsEnc=0, $urlId=0 ,$urlWebPathPart=''){
		if ($urlIsEnc){
			return $urlWebPathPart .'p.php?m=url&t=infoWeb&id='. $urlId;
		}else{
			return $urlStr;
		}
	}


	public static function GoodsList($dataID, $page=0, $domain=''){
		global $GB_WebHost;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
		$retStr = $domain .'goods/?list_'. $dataID . $pageStr .'.html';

		return $retStr;
	}

	public static function GoodsListStr($typeStr, $page=0, $domain=''){
		global $GB_WebHost;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
		$retStr = $domain .'goods/?list_'. $typeStr . $pageStr .'.html';

		return $retStr;
	}

	public static function BbsListStr($typeStr, $page=0, $domain=''){
		global $GB_WebHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
		$retStr = $domain .'message/?list_'. $typeStr . $pageStr .'.html';

		return $retStr;
	}


	public static function BbsList($dataID, $page=0, $domain=''){
		global $GB_WebHost;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
		if ($dataID == 0 && $page <= 1){
			$retStr = $domain .'message/';
		}else{
			$retStr = $domain .'message/?list_'. $dataID . $pageStr .'.html';
		}

		return $retStr;
	}


	public static function BbsID($dataID, $page=0, $domain=''){
		global $GB_WebHost;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_WebHost; }
		if ($page > 1){ $pageStr='_'. $page; }else{ $pageStr=''; }
		$retStr = $domain .'message/?'. $dataID . $pageStr .'.html';

		return $retStr;
	}


	public static function IdcProList($urlDataID, $urlPageID=0, $urlDomain=''){
		global $DB,$GB_WebHost;

		$retStr = '';
		$pageStr= '';
		if (strlen($urlDomain) == 0){ $urlDomain = $GB_WebHost; }
		if ($urlDataID < 0){
			$htmlName = $DB->GetOne('select IPT_htmlName from '. OT_dbPref .'idcProType where IPT_ID='. abs($urlDataID));
			if (strlen($htmlName) > 3){
				$retStr = $urlDomain . $htmlName;
			}else{
				$retStr = $urlDomain .'idcPro.php?dataID='. abs($urlDataID) .'&html=false';
			}
		}else{
			if ($urlPageID > 1){ $pageStr='&page='. $urlPageID; }else{ $pageStr=''; }
			$retStr = $urlDomain .'idcPro.php?dataID='. $urlDataID . $pageStr .'';
		}

		return $retStr;
	}


	public static function GoodsList_pageSign($dataID, $page=0, $domain=''){
		global $GB_JsHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_JsHost; }
		if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
		$retStr = $domain .'goods/?list_'. $dataID . $pageStr .'.html';

		return $retStr;
	}

	public static function GoodsListStr_pageSign($typeStr, $page=0, $domain=''){
		global $GB_JsHost;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_JsHost; }
		if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
		$retStr = $domain .'goods/?list_'. $typeStr . $pageStr .'.html';

		return $retStr;
	}



	public static function BbsListStr_pageSign($typeStr, $page=0, $domain=''){
		global $GB_JsHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_JsHost; }
		if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
		$retStr = $domain .'message/?list_'. $typeStr . $pageStr .'.html';

		return $retStr;
	}

	public static function BbsList_pageSign($dataID, $page=0, $domain=''){
		global $GB_JsHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_JsHost; }
		if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
		$retStr = $domain .'message/?list_'. $dataID . $pageStr .'.html';
		return $retStr;
	}

	public static function BbsID_pageSign($dataID, $page=0, $domain=''){
		global $GB_JsHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_JsHost; }
		if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
		$retStr = $domain .'message/?'. $dataID . $pageStr .'.html';

		return $retStr;
	}


	public static function ListStr_pageSign($typeStr, $page=0, $domain=''){
		global $GB_JsHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_JsHost; }
		switch ($systemArr['SYS_newsListUrlMode']){
			case 'html-2.x':	// news/list_announ.html 、news/list_announ_2.html
				if ($systemArr['SYS_diyInfoTypeDir']==1 && strpos('|announ|new|','|'. $typeStr .'|') !== false){
					if ($page > 1){ $pageStr='index_[page].html'; }else{ $pageStr=''; }
					$retStr = $domain . $typeStr .'/'. $pageStr;
				}else{
					if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
					if (strpos($typeStr,'-') !== false){
						$retStr = $domain .'news/?list_'. $typeStr . $pageStr .'.html';
					}else{
						$retStr = $domain . $systemArr['SYS_newsListFileName'] .'/list_'. $typeStr . $pageStr .'.html';
					}
				}
				break;

			case 'static-3.x':	// news/list_announ.html 、news/list_announ_2.html
				if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
				if (strpos($typeStr,'-') !== false){
					$retStr = $domain .'news/?list_'. $typeStr . $pageStr .'.html';
				}else{
					$retStr = $domain . $systemArr['SYS_newsListFileName'] .'/list_'. $typeStr . $pageStr .'.html';
				}
				break;

			case 'dyn-2.x':	// news/?list_announ.html 、news/?list_announ_2.html
				if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
				$retStr = $domain .'news/?list_'. $typeStr . $pageStr .'.html';
				break;

		}
		return $retStr;
	}

	public static function ListID_pageSign($htmlName, $infoTypeDir, $dataID, $page=0, $domain='', $maxPage=0){
		global $GB_JsHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_JsHost; }
		switch ($systemArr['SYS_newsListUrlMode']){
			case 'html-2.x':
				if ($maxPage > 0 && $maxPage < $page){
					if ($page > 1){ $pageStr = '_[page]'; }else{ $pageStr = ''; }
					$retStr = $domain .'news/?list_'. $dataID . $pageStr .'.html';
				}else{
					if ($systemArr['SYS_diyInfoTypeDir'] == 1 && strlen($infoTypeDir) >= 1){
						if ($page > 1){ $pageStr='index_[page].html'; }else{ $pageStr=''; }
						if (substr($infoTypeDir,-1) != '/'){ $infoTypeDir .= '/'; }
						$retStr = $domain . $infoTypeDir . $pageStr;
					}else{
						if ($htmlName==''){ $htmlName=$dataID; }
						if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
						$retStr = $domain . $systemArr['SYS_newsListFileName'] .'/list_'. $htmlName . $pageStr .'.html';
					}
				}
				break;

			case 'static-3.x':
				if ($htmlName==''){ $htmlName=$dataID; }
				if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
				$retStr = $domain . $systemArr['SYS_newsListFileName'] .'/list_'. $htmlName . $pageStr .'.html';
				break;

			case 'dyn-2.x':
				if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
				$retStr = $domain .'news/?list_'. $dataID . $pageStr .'.html';
				break;

		}
		return $retStr;
	}

	public static function NewsID_pageSign($infoTypeDir, $datetimeDir, $dataID, $page=0, $domain=''){
		global $GB_JsHost,$systemArr;

		$retStr = '';
		$pageStr= '';
		if (strlen($domain) == 0){ $domain = $GB_JsHost; }
		switch ($systemArr['SYS_newsShowUrlMode']){
			case 'html-2.x': case 'static-3.x':
				if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
				if ($systemArr['SYS_htmlInfoTypeDir']==1 && strlen($infoTypeDir)>=1){ $infoTypeHtmlDir=$infoTypeDir; }else{ $infoTypeHtmlDir=''; }
				if ($systemArr['SYS_htmlDatetimeDir']>0 && strlen($datetimeDir)>=1){ $datetimeHtmlDir=$datetimeDir; }else{ $datetimeHtmlDir=''; }
				if ($systemArr['SYS_diyInfoTypeDir']==1){
					$retStr = $domain . $infoTypeHtmlDir . $datetimeHtmlDir . $dataID . $pageStr .'.html';
				}else{
					$retStr = $domain . $systemArr['SYS_newsShowFileName'] .'/'. $infoTypeHtmlDir . $datetimeHtmlDir . $dataID . $pageStr .'.html';
				}
				break;

			case 'dyn-2.x':
				if ($page > 1){ $pageStr='_[page]'; }else{ $pageStr=''; }
				$retStr = $domain .'news/?'. $dataID . $pageStr .'.html';
				break;

		}
		return $retStr;
	}

}

?>